package com.vcms.controller.system;

import com.vcms.controller.customer.TransactionController;
import com.vcms.controller.machine.MachinaryController;
import com.vcms.controller.maintenance.MaintenanceController;
import com.vcms.exception.VMCSException;
import com.vcms.view.simulation.system.SimulatorControlPanel;

/**
 * @author Team 7 PT
 * @version 1.0
 */

public class SimulationController {

	private SimulatorControlPanel scp = null;
	public MainController mCtrl = null;

	public SimulationController(MainController ctrl) {
		mCtrl = ctrl;
		scp = new SimulatorControlPanel(this);
		// scp.setSimulationActive (false);
	}

	public SimulatorControlPanel getSimulatorControlPanel() {
		// scp.setSimulationActive (false);
		return (scp);
	}

	public void displaySimulatorControlPanel() {
		scp.display();
	}

	public void stop() {
		mCtrl.closeDown();
	}

	public void closeDown() {
		scp.closeDown();
	}

	public void start() {
		scp.setSimulationActive(true);
		scp.setActive(SimulatorControlPanel.BEGIN, false);
		// scp.setButtonState(SimulatorControlPanel.BEGIN, false);
	}

	// public void setButtonState(char id, boolean st){
	// scp.setButtonState(id, st);
	// }

	public void setSimulationActive(boolean vl) {
		scp.setSimulationActive(vl);
	}

	
	public void setupSimulator() {
		@SuppressWarnings("unused")
		MaintenanceController maintenanceCtrl = mCtrl.getMaintenanceController();
		MachinaryController machinaryController =  mCtrl.getMachinaryController();
		scp.setActive(SimulatorControlPanel.ACT_MACHINERY, false);
		// setButtonState(SimulatorControlPanel.ACT_MACHINERY, false);
		try {
			// activate when not login
			// always diaply the door locked; isOpen false
			machinaryController.displayMachineryPanel();
			// display drink stock;
			machinaryController.displayDrinkStock();
			// display coin quantity;
			machinaryController.displayCoinStock();
			// storeCtrl.setDoorState(true);
			machinaryController.displayDoorState();
		} catch (VMCSException e) {
			System.out.println("SimulationController.setupSimulator:" + e);
		}
	}

	/**
	 * set up customer panel Needed to be filled in by student;
	 */
	public void setupCustomer(char mode) {
		TransactionController transactionController = mCtrl.getTransactionController();
		scp.setActive(SimulatorControlPanel.ACT_CUSTOMER, false);
		scp.setActive(SimulatorControlPanel.ACT_CUSTOMER_NUMERIC, false);
		scp.setActive(SimulatorControlPanel.ACT_CUSTOMER_ALPHANUMERIC, false);
		transactionController.displayCustomerPanel(mode);
		
	}

	public void setupMaintainer() {
		MaintenanceController mctrl;
		mctrl = mCtrl.getMaintenanceController();
		scp.setActive(SimulatorControlPanel.ACT_MAINTAINER, false);
		mctrl.displayMaintenancePanel();
	}
	
	public MainController getMainController() {
		return mCtrl;
	}

}
